package com.example.musicrecorder;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.io.IOException;
import java.util.List;

public class mylist extends BaseAdapter {
    private List<Song> songlist;
    private int resource;//显示列表项的Layout

    private LayoutInflater inflater;//界面生成器

    private Context context;
    public mylist(List<Song> songlist,Context context,int resource){

        this.context=context;
        this.songlist=songlist;
        this.resource=resource;
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return songlist.size();
    }

    @Override
    public Object getItem(int i) {
        return songlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view == null){
            view = inflater.inflate(resource, null);
        }
        final Song song = songlist.get(i);
        TextView sname =(TextView) view.findViewById(R.id.songna);
//设置ListView中的Item中的TextView
        sname.setText(song.getSname());

        TextView sid=(TextView) view.findViewById(R.id.songid);
        String s= String.valueOf(song.getId());
        sid.setText(s);
        return view;
    }
}
